import uuid
from datetime import datetime

from sqlalchemy import (
    Column,
    UUID,
    PrimaryKeyConstraint,
    Index, String, DateTime
)
from sqlalchemy.dialects.postgresql import JSONB

from internal.extension.extension_db import db


class App(db.Model):
    __tablename__ = "apps"
    __table_args__ = (
        PrimaryKeyConstraint("id", name="pk_app_id"),
        Index("idx_app_account_id", "account_id"),
    )
    id = Column(UUID, default=uuid.uuid4(), nullable=False)
    account_id = Column(UUID, nullable=False)
    name = Column(String(255), default="", nullable=False)
    icon = Column(String(255), default="", nullable=False)
    status = Column(String(255), default="", nullable=False)
    config = Column(JSONB, default={}, nullable=False)
    update_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
    created_at = Column(DateTime, default=datetime.now)
